#!/bin/tcsh

###############################################################################
#
# This script runs first the RUBBoS browsing mix, then the read/write mix 
# for each rubbos.properties_XX specified where XX is the number of emulated
# clients. Note that the rubbos.properties_XX files must be configured
# with the corresponding number of clients.
# In particular set the following variables in rubis.properties_XX:
# httpd_use_version = Servlets
# workload_number_of_clients_per_node = XX/number of client machines
# workload_transition_table = yourPath/RUBBoS/workload/transitions.txt 
#
# This script should be run from the RUBBoS/bench directory on the local 
# client machine. 
# Results will be generated in the RUBBoS/bench directory.
#
################################################################################

setenv SERVLETDIR $RUBBOS_HOME/Servlets

# Go back to RUBBoS root directory
cd ..

foreach j ( `seq 0 0`)

  #Read/Write 
  cp --reply=yes ./workload/user_default_transitions.txt ./workload/user_transitions.txt
  cp --reply=yes ./workload/author_default_transitions.txt ./workload/author_transitions.txt

  scp ./workload/user_default_transitions.txt ${CLIENT1_HOST}:${RUBBOS_HOME}/workload/user_transitions.txt
  scp ./workload/author_default_transitions.txt ${CLIENT1_HOST}:${RUBBOS_HOME}/workload/author_transitions.txt

  scp ./workload/user_default_transitions.txt ${CLIENT2_HOST}:${RUBBOS_HOME}/workload/user_transitions.txt
  scp ./workload/author_default_transitions.txt ${CLIENT2_HOST}:${RUBBOS_HOME}/workload/author_transitions.txt
	
  foreach i (rubbos.properties_1 rubbos.properties_2 rubbos.properties_3 rubbos.properties_4 rubbos.properties_5 rubbos.properties_6 rubbos.properties_7 rubbos.properties_8 rubbos.properties_9 rubbos.properties_10 ) 

    ./stop_all0.sh
    sleep 5
    ./start_all0.sh
    sleep 5
    

    cp --reply=yes bench/$i Client/rubbos.properties
    scp bench/$i ${CLIENT1_HOST}:${RUBBOS_HOME}/Client/rubbos.properties
    scp bench/$i ${CLIENT2_HOST}:${RUBBOS_HOME}/Client/rubbos.properties


    bench/flush_cache 9000000    
    #bench/flush_cache `/usr/bin/head -n /proc/meminfo | awk '{print $2}'` 
    #ssh $HTTPD_HOST "$RUBBOS_HOME/bench/flush_cache  `/usr/bin/head -n /proc/meminfo | awk '{print $2}'` " 	# web server
    #ssh $MYSQL_MASTER_HOST "$RUBBOS_HOME/bench/flush_cache `/usr/bin/head -n /proc/meminfo | awk '{print $2}'`"	# database
    #ssh $TOMCAT_HOST1 "$RUBBOS_HOME/bench/flush_cache `/usr/bin/head -n /proc/meminfo | awk '{print $2}'` " 	# servlet server
#    ssh $CLIENT1_HOST "$RUBBOS_HOME/bench/flush_cache `/usr/bin/head -n /proc/meminfo | awk '{print $2}'` 990000"	# remote client
#    ssh $CLIENT2_HOST "$RUBBOS_HOME/bench/flush_cache `/usr/bin/head -n /proc/meminfo | awk '{print $2}'` 890000"	# remote client
    make emulator
  end

  # restart all services
  ./stop_all0.sh
  sleep 5

end
